package com.assistant;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.util.EntityUtils;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.converter.StringHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;

@Slf4j
public class RestUtil {
    public static void call(Integer id) {
        RestTemplate restTemplate = new RestTemplate();
        restTemplate.getMessageConverters()
                .stream()
                .filter(StringHttpMessageConverter.class::isInstance)
                .forEach(converter -> ((StringHttpMessageConverter) converter).setDefaultCharset(StandardCharsets.UTF_8));
        String url = "http://api.trusteeship.house.lianjia.com/tool/data/callAigcChatSummary";
        //构造header
        HttpHeaders headers = new HttpHeaders();
        headers.add("content-type", MediaType.APPLICATION_JSON_VALUE);
        headers.add("Lianjia-Ucid", "1000000029176198");
        JSONArray postBody = new JSONArray();
        postBody.add(id);
        HttpEntity<String> httpEntity = new HttpEntity<>(postBody.toString(), headers);
        String jsonObject = null;
        try {
            //response
            log.info("请求 request url:{},body:{}", url, httpEntity);
            jsonObject = restTemplate.postForObject(url, httpEntity, String.class);
            log.info("请求 response:{}", jsonObject);
        } catch (Exception e) {
            log.error("请求：url:{}，请求参数：{}，", url, JSONObject.toJSONString(httpEntity),e);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        List<Integer> ids = Lists.newArrayList(
                1054251,1054252,1054253,1054427,1054428,1054433,1054468,1054491,1054332,1054333,1054335,1054336,1054337,1054339,1054340,1054342,1054344,1054347,1054349,1054350,1054353,1054354,1054356,1054357,1054358,1054359,1054360,1054361,1054363,1054367,1054372,1054373,1054374,1054375,1054377,1054378,1054379,1054380,1054381,1054382,1054385,1054386,1054396,1054398,1054399,1054401,1054402,1054403,1054404,1054405,1054407,1054408,1054409,1054411,1054412,1054415,1054419,1054420,1054421,1054423,1054424,1054437,1054445,1054447,1054448,1054449,1054453,1054492,1054493,1054494,1054498,1054504,1054505,1054507,1054509,1054511,1054438,1054443,1054452,1054454,1054458,1054472,1054473,1054474,1054475,1054476,1054480,1054481,1054482,1054485,1054487,1054488,1054489,1054502,1054503,1054510,1054512,1054513,1054515,1054517,1054519,1054520,1054522,1054525,1054526,1054532,1054535,1054536,1054537,1054538,1054539,1054540,1054544,1054546,1054547,1054548,1054549,1054553,1054554,1054555,1054557,1054558,1054559,1054560,1054566,1054567,1054568,1054570,1054573,1054574,1054575,1054579,1054582,1054583,1054592,1054593,1054596,1054597,1054603,1054605,1054608,1054611,1054614,1054615,1054616,1054617,1054618,1054620,1054623,1054658,1054483,1054569,1054578,1054584,1054585,1054586,1054587,1054589,1054594,1054595,1054599,1054600,1054612,1054625,1054827,1054862,1054660,1054661,1054662,1054665,1054666,1054667,1054668,1054669,1054670,1054671,1054673,1054674,1054675,1054676,1054677,1054679,1054682,1054683,1054685,1054687,1054688,1054689,1054690,1054691,1054695,1054697,1054698,1054700,1054702,1054704,1054707,1054708,1054709,1054710,1054712,1054714,1054715,1054716,1054718,1054719,1054720,1054721,1054722,1054724,1054725,1054726,1054727,1054728,1054730,1054733,1054734,1054736,1054738,1054742,1054744,1054745,1054746,1054747,1054748,1054750,1054754,1054755,1054861,1054864,1054865,1054867,1054868,1054872,1054874,1054893,1054894,1054895,1054964,1055052,1054124,1054125,1054126,1054127,1054130,1054131,1054132,1054133,1054134,1054135,1054136,1054137,1054138,1054139,1054142,1054149,1054150,1054153,1054159,1054162,1054164,1054165,1054166,1054168,1054170,1054171,1054172,1054177,1054179,1054182,1054183,1054184,1054185,1054186,1054187,1054188,1054189,1054190,1054191,1054257,1054258,1054260,1054261,1054262,1054263,1054265,1054267,1054268,1054269,1054273,1054276,1054822,1054823,1054828,1054830,1054831,1054833,1054835,1054836,1054837,1054842,1054845,1054847,1054848,1054853,1054855,1054856,1054858,1054876,1054877,1054878,1054880,1054881,1054882,1054883,1054885,1054886,1054887,1054888,1054889,1054890,1054891,1054892,1054897,1054898,1054899,1054901,1054902,1055064,1055088,1055089,1053666,1053667,1053670,1053671,1053672,1053675,1053676,1053677,1053678,1053685,1053686,1053687,1053693,1053722,1053725,1053917,1054278,1054279,1054281,1054283,1054285,1054286,1054288,1054289,1054290,1054291,1054292,1054295,1054299,1054302,1054303,1054304,1054305,1054308,1054309,1054310,1054311,1054315,1054316,1054317,1054318,1054322,1054323,1054324,1054390,1054432,1054435,1054436,1054460,1054461,1054462,1054463,1054464,1054467,1054469,1054530,1054591,1054628,1054632,1054634,1054635,1054637,1054638,1054639,1054642,1054965,1054967,1054969,1054971,1054974,1054979,1054980,1054981,1054982,1054983,1054984,1054985,1054987,1054989,1054990,1054995,1054996,1054997,1055004,1055005,1055006,1055007,1055008,1055009,1055010,1055013,1055015,1055017,1055018,1055021,1055022,1055024,1055025,1055026,1055027,1055028,1055029,1055030,1055033,1055034,1055037,1055038,1055040,1055041,1055043,1055045,1055046,1055047,1055048,1055049,1055051,1055053,1055055,1055056,1055059,1055061,1055096,1055097,1055100,1055102,1055103,1055105,1055107,1053665,1053683,1053684,1053692,1053723,1053916,1053918,1054325,1054391,1054392,1054630,1054643,1054644,1055036,1055058,1055062,1055140,1055144,1055149,1055150,1055151,1055153,1055154,1055157,1055159,1055162,1055163,1055164,1055167,1055168,1055170,1055173,1055175,1055189,1055190,1055191,1055192,1055193,1055195,1055196,1055197,1055199,1055200,1055201,1055202,1055203,1055205,1055206,1055209,1055210,1055212,1055213,1055215,1055218,1055219,1055220,1055221,1055222,1055224,1055225,1055227,1055229,1055231,1055232,1055233,1055238,1055239,1055244,1055245,1055247,1055249,1055251,1055252,1055254,1055255,1055257,1055260,1055261,1055263,1055265,1055268,1055407,1055459,1055273,1055274,1055275,1055276,1055279,1055280,1055281,1055283,1055287,1055290,1055291,1055292,1055293,1055294,1055296,1055299,1055302,1055303,1055306,1055307,1055309,1055310,1055311,1055313,1055314,1055335,1055336,1055339,1055342,1055344,1055345,1055348,1055351,1055352,1055356,1055357,1055358,1055360,1055361,1055367,1055368,1055371,1055373,1055374,1055375,1055378,1055379,1055381,1055383,1055391,1055392,1055393,1055395,1055399,1055401,1055402,1055403,1055405,1055406,1055409,1055410,1055412,1055414,1055416,1055417,1055419,1055420,1055423,1055424,1055427,1055430,1055432,1055436,1055439,1055520,1055380,1055388,1055490,1055495,1055503,1055511,1055525,1055529,1055532,1055533,1055536,1055539,1055542,1055543,1055544);
        int  i=0;
        for (Integer id : ids) {
            i++;
            System.out.println("id="+id+" index="+i);
            call(id);
            Thread.sleep(1000);
        }
//        call(1054192);
    }
}
